home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1995 April / Internet Tools.iso / applic / ncsa / Mac / Telnet2.6 / prerelease / d4 / Telnet2.6.1d4.src.sit.hqx / Telnet 2.6.1d4 source / source / init / init.c oldauth < prev    next >
Encoding:
Text File  |  1994-06-21  |  12.8 KB  |  476 lines

  1. /*
  2. *    init.c
  3. *    Top level of init code & general initialization routines
  4. *    Called only by main()
  5. *
  6. *****************************************************************
  7. *    NCSA Telnet for the Macintosh                                *
  8. *                                                                *
  9. *    National Center for Supercomputing Applications                *
  10. *    Software Development Group                                    *
  11. *    152 Computing Applications Building                            *
  12. *    605 E. Springfield Ave.                                        *
  13. *    Champaign, IL  61820                                        *
  14. *                                                                *
  15. *    Copyright (c) 1986-1992,                                    *
  16. *    Board of Trustees of the University of Illinois                *
  17. *****************************************************************
  18. *  Revisions:
  19. *  7/92        Telnet 2.6:    Initial version.  Jim Browne
  20. */
  21.  
  22. #ifdef MPW
  23. #pragma segment INIT
  24. #endif
  25.  
  26. #include "TelnetHeader.h"
  27.  
  28. #include <string.h>
  29. #include <Folders.h>
  30. #include <Script.h>
  31. #include <stdio.h>
  32. #include <GestaltEqu.h>
  33. #include <AppleEvents.h>
  34.  
  35. #include "init.proto.h"
  36. #include "debug.h"
  37. #include "mainseg.proto.h"        /* For forcequit() proto */
  38. #include "iNetwork.proto.h"    /* For initnet proto */
  39. #include "macros.proto.h"        /* For setmacro proto */
  40. #include "wind.h"        /* For WindRec definition */
  41. #include "rsmac.proto.h"        /* For RSgetwindow & RSnewwindow protos */
  42. #include "DlogUtils.proto.h"    /* For VersionNumber, UItemAssign, GetNewMyDialog protos */
  43. #include "Sets.proto.h"        // For readconfig proto
  44. #include "prefs.proto.h"
  45. #include "vr.h"            /* For VRinit proto */
  46. #include "vsdata.h"
  47. #include "vsinterf.proto.h"    /* For VSinit proto */
  48. #include "vgtek.proto.h"        /* For VGinit proto */
  49. #include "vrrgmac.proto.h"    /* For MacRGinit proto */
  50. #include "telneterrors.h"        /* for DoError proto */
  51. #include "tekrgmac.proto.h"    /* For RGMalloc proto */
  52. #include "menuseg.proto.h"
  53. #include "translate.proto.h"
  54. #include "dnr.proto.h"    // For OpenResolver proto
  55. #ifdef newauth            // (RW)
  56. #include "tnae.h"
  57. #include "authencrypt.h"
  58. #include "authencrypt.proto.h"
  59. #else
  60. #include "desproto.h"
  61. #endif
  62. #include "ae.proto.h"            // For AppleEvent handlers
  63. #include "MacBinary.h"
  64. #include "binsubs.proto.h"        // For init_mb_files proto
  65.  
  66.  
  67. /*--------------------------------------------------------------------------------*/
  68. #define CurrentVersion 1                /* Last known SysEnvirons version */
  69. #define HFSPtr ((long *)1014)
  70.  
  71. extern    char *tempspot;                /* for temp storage only */
  72.  
  73. extern    unsigned char
  74.     *macro[10];        /* the wonderful macro package .... */
  75.  
  76. extern    Cursor *theCursors[];
  77.  
  78. extern    WindRec
  79.     *screens,        /* Window Records (VS) for :    Current Sessions */
  80.     *ftplog;            /*                                FTP Log             */
  81. extern    MenuHandle    myMenus[];
  82.  
  83. OSErr        io;
  84. char        *mungbuf;
  85. SysEnvRec    theWorld;                        /* System Environment record */
  86. short        TempItemsVRefNum;
  87. long        TempItemsDirID;
  88. Boolean        gKeyboardHasControlKey, gAEavail;
  89.  
  90. Boolean encryptOK;                // true if des encryption routines available
  91. Boolean authOK;                    // true if authentication driver available
  92.  
  93. /*    checkCONF - check if the user clicked on a configuration file */
  94. void checkCONF( void)
  95. {
  96.     short    i,mess,count;
  97.     AppFile    theFile;
  98.     FSSpec    FileSpec;
  99.     long    junk = 0;
  100.  
  101.     if (gAEavail) return;    // If AppleEvents are available, we'll get ODOCs
  102.  
  103. #ifndef __powerpc__
  104.     CountAppFiles(&mess,&count);
  105.     if (mess==1) return;
  106.     if (count<1) return;
  107.     for(i=1;i<=count;i++) {
  108.         GetAppFiles(i, &theFile);
  109.         if (theFile.fType=='CONF') {
  110.             ClrAppFiles(i);
  111.             BlockMove(&theFile.fName, FileSpec.name, (*theFile.fName)+1); // pstring copy theFile.fName -> FileSpec.name
  112.             GetWDInfo(theFile.vRefNum, &FileSpec.vRefNum, &FileSpec.parID, &junk);
  113.             readconfig(FileSpec);    /* BYU LSC */
  114.             }
  115.         }
  116. #endif
  117.     return;
  118. }
  119.  
  120. void initmacros( void)
  121. {
  122.     short i;
  123.  
  124.     for (i=0; i<10 ; i++) {
  125.         macro[i] = (unsigned char *) NewPtrClear(256);        /* BYU LSC */
  126.         if (macro[i]== NULL) 
  127.             {            /* Cant allocate space for the Macros */
  128.             DoError(102 | MEMORY_ERRORCLASS, LEVEL3,NULL);    
  129.             forcequit();
  130.             }
  131.         setmacro( i, (unsigned char *) "");        /* BYU LSC */
  132.         }
  133. }
  134.  
  135. void initEvents( void)
  136. {
  137.     EventRecord myEvent;
  138.  
  139.     FlushEvents(everyEvent - diskEvt,0);    /* Don't Let 'em get off without seeing it. */
  140.  
  141.     WaitNextEvent(everyEvent, &myEvent, gApplicationPrefs->TimeSlice, 0L);    /* WNE always avail */
  142.     WaitNextEvent(everyEvent, &myEvent, gApplicationPrefs->TimeSlice, 0L);
  143. }
  144.  
  145. /* initftplog - initialize the FTP log window */
  146. void initftplog( void)
  147. {
  148.     Rect prect;
  149.  
  150.     SetRect(&prect, 300,256,512,384);
  151.  
  152.     ftplog = (WindRec *) NewPtrClear(sizeof(WindRec));
  153.     
  154.     ftplog->vs=RSnewwindow( &prect, 50, 80, 24,
  155.                     "\pFTP Log", 1, DefFONT, DefSIZE, gFTPServerPrefs->ShowFTPlog,
  156.                         1,0);    /* NCSA 2.5 */
  157.  
  158.     ftplog->wind = RSgetwindow( ftplog->vs);
  159.     ((WindowPeek)ftplog->wind)->windowKind = WIN_LOG;
  160.     
  161.     VSwrite(ftplog->vs,"\033[24;0H",7);        /* Move to bottom of screen */
  162.     ftplog->active=0;                         /* Meaningless */
  163.     ftplog->port=0;                            /* As is this */
  164.     ftplog->termstate=VTEKTYPE;
  165. }
  166.  
  167.   /* copies a specified cursor from a resource into a nonrelocatable block
  168.     and returns a pointer to it in *result. */
  169. void loadcursor( short CursorID, CursPtr *result)
  170. {
  171.     CursHandle tempcurs;
  172.     OSErr Err;
  173.  
  174.     *result = nil;
  175.     do /* once */
  176.       {
  177.         tempcurs = GetCursor(CursorID);
  178.         Err = ResError();
  179.         if (Err != noErr)
  180.             break;
  181.         *result = (CursPtr) NewPtr(sizeof(Cursor));        /* BYU LSC */
  182.         Err = MemError();
  183.         if (Err != noErr)
  184.             break;
  185.         LoadResource((Handle) tempcurs); /* in case it was purged */
  186.         Err = ResError();
  187.         if (Err != noErr)
  188.             break;
  189.         BlockMove((Ptr) *tempcurs, (Ptr) *result, sizeof(Cursor));
  190.       }
  191.     while (false);
  192.     if (Err != noErr)
  193.       {
  194.         if (*result != nil)
  195.             DisposPtr((Ptr) *result);
  196.         *result = &qd.arrow;
  197.       }
  198. } /* loadcursor */
  199.  
  200. /* initmcurs - Set up the mouse Cursors
  201.  *        NOTE: debug tells if the bug or the pointer is to be used as dflt.*/
  202. void initmcurs ( short debug) 
  203. {
  204.     loadcursor(rWatchCursor, &theCursors[watchcurs]);
  205.     loadcursor(rCrossCursor, &theCursors[graphcurs]);
  206.     loadcursor(rPOSCURS, &theCursors[poscurs]);
  207.     loadcursor(rBeamCursor, &theCursors[textcurs]);
  208.     loadcursor(rGINCURS, &theCursors[gincurs]);
  209.     loadcursor(rXferCURS, &theCursors[xfercurs]);
  210.     if (debug)
  211.         loadcursor(rDbugCURS, &theCursors[normcurs]);
  212.     else
  213.         theCursors[normcurs] = &qd.arrow;
  214.     SetCursor(theCursors[normcurs]);
  215. }
  216.  
  217. /*     If a file with the filetype "DBUG" was sent to us, set the debug mode. */
  218. short checkdebug( void)
  219. {
  220.     short i,mess,count;
  221.     AppFile theFile;
  222.     long junk = 0;
  223.  
  224.     if (gAEavail) return(FALSE);    //     Don't use CountAppFiles if AppleEvents
  225.                                     //    are available.
  226. #ifndef __powerpc__    
  227.     CountAppFiles(&mess,&count);
  228.     if (mess==1) return(FALSE);
  229.     if (count<1) return(FALSE);
  230.     for(i=1;i<=count;i++) {
  231.         GetAppFiles(i, &theFile);
  232.         if (theFile.fType=='DBUG') {
  233.             ClrAppFiles(i);
  234.             return(TRUE);
  235.             }
  236.         }
  237.     return(FALSE);
  238. #endif
  239. }
  240.  
  241. void InquireEnvironment( void)
  242. {
  243.     OSErr    err;
  244.     Boolean HFSflag;
  245.     long    response;
  246.     
  247.     long *HFSp=(long *)1014L;
  248.     
  249.     HFSflag= (*HFSp) > 0L;
  250.     if (!HFSflag) FatalAlert(NEED_HFS_ERR, 0, 0);
  251.  
  252.     err = SysEnvirons(CurrentVersion, &theWorld);
  253.     
  254.     if (err == envVersTooBig) FatalAlert(SYS_ENVIRON_ERR, 0, 0);
  255.     
  256.     if (theWorld.systemVersion < 0x0600) FatalAlert(SYSTEM_VERS_ERR, 0, 0);
  257.     
  258.     if (theWorld.machineType < 0) FatalAlert(ROM_VERS_ERR, 0, 0);
  259.     
  260.     // If there is a problem w/Gestalt, assume our keyboard has a Control key.
  261.     // Otherwise, we assume we have a control key unless a Mac or MacPlus keyboard is
  262.     // present.
  263.         
  264.     if ((err = Gestalt(gestaltKeyboardType, &response)) != noErr)
  265.         gKeyboardHasControlKey = TRUE;
  266.     else
  267.         gKeyboardHasControlKey = !(    (response == gestaltMacKbd) ||
  268.                                     (response == gestaltMacAndPad) ||
  269.                                     (response == gestaltMacPlusKbd) );
  270.                                     
  271.     /* System 6.0 and up ALWAYS has WNE trap! */
  272. }
  273.  
  274. void initmac( void)
  275. {
  276.     EventRecord myEvent;
  277.     short     i;
  278.     long    gestaltvalue;
  279.     OSErr    err;
  280.  
  281.     InitGraf(&qd.thePort);
  282.     InitFonts();
  283.     InitWindows();
  284.     InitMenus();
  285.     TEInit();
  286.     InitDialogs(0L);                /* No resume proc */
  287.     InitCursor();
  288.     
  289.     TelInfo = (TelInfoRec *)NewPtrClear(sizeof(TelInfoRec));
  290.     mungbuf = (char *)NewPtrClear(1024);
  291.     tempspot = (char *)NewPtrClear(256);
  292.     gApplicationPrefs = (ApplicationPrefs *)NewPtrClear(sizeof(ApplicationPrefs));
  293.     gFTPServerPrefs = (FTPServerPrefs *)NewPtrClear(sizeof(FTPServerPrefs));
  294.     screens = (WindRec *)NewPtrClear(MaxSess*sizeof(WindRec));
  295.  
  296.     InquireEnvironment();
  297.  
  298.     for (i=1;i<12;i++)
  299.         EventAvail( 0xffff, &myEvent);
  300.     
  301.     err = Gestalt(gestaltAppleEventsAttr, &gestaltvalue);        // See if AppleEvents are available
  302.     gAEavail = (!err && ((gestaltvalue >> gestaltAppleEventsPresent) & 0x0001));
  303.     
  304.     if (gAEavail) {
  305.         if (err = AEInstallEventHandler(kCoreEventClass,kAEOpenApplication,
  306.                                             MyHandleOAppUPP,0,FALSE))
  307.             FatalAlert(AE_PROBLEM_ERR, 0, 0);
  308.         if (err = AEInstallEventHandler(kCoreEventClass,kAEOpenDocuments,
  309.                                             MyHandleODocUPP,0,FALSE))
  310.             FatalAlert(AE_PROBLEM_ERR, 0, 0);
  311.         if (err = AEInstallEventHandler(kCoreEventClass,kAEPrintDocuments,
  312.                                             MyHandlePDocUPP,0,FALSE))
  313.             FatalAlert(AE_PROBLEM_ERR, 0, 0);
  314.         if (err = AEInstallEventHandler(kCoreEventClass,kAEQuitApplication,
  315.                                             MyHandleQuitUPP,0,FALSE))
  316.             FatalAlert(AE_PROBLEM_ERR, 0, 0);
  317.         }
  318.  
  319.     TelInfo->screenRect = qd.screenBits.bounds;            /* well, they have to be set */
  320.                                                 /* somewhere, where else ? */
  321.     SetRect(&TelInfo->dragRect, 4, 24, TelInfo->screenRect.right-4,
  322.                         TelInfo->screenRect.bottom-4);
  323. }
  324.  
  325. void DoTheGlobalInits(void)
  326. {
  327.     long junk = 0;
  328.     ParamBlockRec pb;
  329.     
  330.     TelInfo->ScrlLock=0;
  331.     TelInfo->ftplogon=0;
  332.     TelInfo->done=0;
  333.     TelInfo->MacBinary=0;
  334.     TelInfo->numwindows=0;
  335.     TelInfo->CONFstate=0;
  336.     TelInfo->CONFactive=0;
  337.     TelInfo->SettingsFile=-1;
  338.     TelInfo->ApplicationFile = CurResFile();
  339.     TelInfo->ginon   = 0;
  340.     TelInfo->xferon  = 0;
  341.     TelInfo->graphs = 0;
  342.     TelInfo->debug = 1;
  343.     TelInfo->myfronttype = NO_WINDOW;
  344.     TelInfo->myfrontvs = 0;
  345.     TelInfo->suspended = FALSE;
  346.     TelInfo->myfrontwindow = 0L;    
  347.     TelInfo->myfrontRgn = 0L;    
  348.     TelInfo->lastCursor = 0L;
  349.     TelInfo->DefaultDirVRefNum = -1;
  350.     TelInfo->FTPClientVRefNum = -1;
  351.     TelInfo->DefaultDirDirID = 2;
  352.     TelInfo->FTPClientDirID = 2;
  353.     
  354.     pb.ioParam.ioNamePtr = 0L;
  355.     PBGetVol(&pb, FALSE);            /* see Tech Note 140 for implications of this */
  356.  
  357.     GetWDInfo(pb.ioParam.ioVRefNum, &(TelInfo->ApFolder.vRefNum), &(TelInfo->ApFolder.parID), &junk);
  358.     TelInfo->ApFolder.name[0] = 0;
  359.  
  360.     FindFolder( kOnSystemDisk, kSystemFolderType, kCreateFolder,
  361.                     &(TelInfo->SysFolder.vRefNum), &(TelInfo->SysFolder.parID));
  362.     TelInfo->SysFolder.name[0]=0;
  363.  
  364.     FindFolder( kOnSystemDisk, kPreferencesFolderType, kCreateFolder,
  365.                     &(TelInfo->PrefFolder.vRefNum), &(TelInfo->PrefFolder.parID));
  366.     TelInfo->PrefFolder.name[0]=0;
  367.     
  368.     FindFolder( kOnSystemDisk, kTemporaryFolderType, kCreateFolder, &TempItemsVRefNum, &TempItemsDirID);
  369. }
  370.  
  371. void init (void)
  372. {
  373.     long        s;
  374.     DialogPtr     dtemp;        /* Used for dialog display */
  375.  
  376.     FlushEvents(everyEvent,0);
  377.     initmac();                /* initialize Macintosh stuff */
  378.     
  379.     DoTheGlobalInits();
  380.  
  381.     OpenPreferencesFile();
  382.     LoadPreferences();
  383.     UnloadSeg(&LoadPreferences);
  384.     
  385.     setupmenu(gApplicationPrefs->CommandKeys);
  386.  
  387.     dtemp = GetNewMyDialog(FirstDLOG, NULL, kInFront, (void *)ThirdCenterDialog);    /* opening dialog */
  388.     UItemAssign( dtemp, 2, VersionNumberUPP);
  389.     DrawDialog(dtemp);                                        /* while we init everything */
  390.  
  391.     trInit(myMenus[National]);    /* LU: Initialize translation routines; must be done */
  392.                                 /* LU: prior to checkdebug(), since even the debug      */
  393.                                 /* LU: output goes through the translation routines. */
  394.     UnloadSeg(&trInit);
  395.  
  396.     TelInfo->debug=checkdebug();        /* must return TRUE or FALSE */
  397.     
  398.     initmcurs(TelInfo->debug);        /* init the mouse cursor */
  399.     SetCursor(theCursors[watchcurs]);
  400.  
  401.     if (RGMalloc()) {        
  402.         DoError(103 | MEMORY_ERRORCLASS, LEVEL3, NULL);
  403.         forcequit();
  404.     }                        
  405.     UnloadSeg(&RGMalloc);
  406.     
  407.     VGalloc();                        /* BYU - save global space */
  408.     UnloadSeg(&VGalloc);
  409.     
  410.     if (VSinit(MaxSess+2)) {        /* initialize the Virtual Screen */
  411.         DoError(104 | MEMORY_ERRORCLASS, LEVEL3, NULL);
  412.         forcequit();
  413.     }
  414.     UnloadSeg(&VSinit);
  415.     
  416.     InitDebug();
  417.     initftplog();                    /* allocate/initialize ftp log screen */
  418.  
  419.     VGinit();                        /* initialize Virtual Graphics after VS so that */
  420.                                     /* init messages can come on console screen */
  421.     UnloadSeg(&VGinit);
  422.     
  423.     VRinit();
  424.     UnloadSeg(&VRinit);
  425.     
  426.     MacRGinit();
  427.     UnloadSeg(&MacRGinit);
  428.     
  429.     init_mb_files();                /* Initialize file id's to closed state */
  430.     UnloadSeg(init_mb_files);
  431.  
  432.     initnet();                        /* initialize network stuff */
  433.     switchMenus(gApplicationPrefs->CommandKeys);
  434.  
  435.     TelInfo->done = FALSE;            // We're not quitting yet.
  436.  
  437.     SetCursor(theCursors[normcurs]);
  438.  
  439.     initmacros();
  440. //    initEvents();
  441.  
  442.     io = OpenResolver(NULL);
  443.  
  444.     if (io) {                                
  445.         DialogPtr theErrDialog;
  446.         short itemhit = 0;
  447.  
  448.         theErrDialog = GetNewDialog(RESOLVERERROR, NULL, kInFront);
  449.         DrawDialog(theErrDialog);
  450.         while (!itemhit)
  451.             ModalDialog(DLOGwOKUPP,&itemhit);
  452.         DisposDialog(theErrDialog);
  453.         }
  454.     
  455.     updateMenuChecks();
  456.     DoTheMenuChecks();
  457.  
  458.     checkCONF();                     /* Did user click on a set? */
  459.  
  460.     DisposDialog(dtemp);            /* Remove the splashbox...  */
  461.  
  462.     encryptOK = authOK = true;
  463. #ifdef newauth                            /* (RW) */
  464.     if (!auth_encrypt_init()) {
  465.         encryptOK = false;
  466.         authOK = false;
  467.     }
  468. #else
  469.     if (s = init_cornell_des()) {
  470.         encryptOK = false;
  471.         if (s == -2)                /* if no kdriver */
  472.             authOK = false;
  473.     }
  474. #endif
  475. }
  476.